package office.action.hr;

import java.util.List;
import office.action.hr.form.StationChangeForm;
import office.action.hr.wrapper.StationChangeWrapper;
import office.service.hr.IStationChangeService;
import platform.common.action.BaseAction;
import platform.util.Util;

public class StationChangeAction extends BaseAction{
	private static final long serialVersionUID = 1L;
	private IStationChangeService stationChangeService;
	private StationChangeForm objctForm;
	private String id;
	private List<StationChangeWrapper> wrapperList;
	@SuppressWarnings("unchecked")
	private List changeTypeList;
	/**
	 * 获取岗位异动列表
	 * @return
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	public String getListStationChange()throws Exception{
		objctForm = new StationChangeForm();
		//TODO 
		objctForm.setUserId(getUserId());
		objctForm.setCheckRole(getUserRoleName());
		objctForm.setDeptId(getUserDepartmentId());
		objctForm.setCompanyId(getUserCompanyId());
		objctForm.setRoleDFlag(getRoleDFlag());
		//根据用户获取数据列表(查看内容为：自己提交的和需要审批的数据)
		//wrapperList = stationChangeService.getByUserId(uesrId);
		wrapperList = stationChangeService.getStationChangeList(objctForm);
		return "showList";
	}
	
	/**
	 * 初始化可用操作
	 * @return
	 * @throws Exception
	 */
	public String gotoEditXml()throws Exception{
		objctForm = stationChangeService.getFindById(id);
		return "editXml";
	}
	
	/**
	 * 跳转到编辑页面
	 * @return
	 * @throws Exception
	 */
	public String gotoAdd()throws Exception{
		changeTypeList = Util.parsePropertiesReturnList("office","changeType.size");
		objctForm = new StationChangeForm();
		objctForm.setUserId(getUserId());
		objctForm.setName(getUserCname());
		return "gotoEdit";
	}
	
	/**
	 * 跳转到编辑页面
	 * @return
	 * @throws Exception
	 */
	public String gotoEdit()throws Exception{
		objctForm = stationChangeService.getFindById(id);
		changeTypeList = Util.parsePropertiesReturnList("office","changeType.size");
		return "gotoEdit";
	}
	/**
	 * 添加或编辑数据
	 * @return
	 * @throws Exception
	 */
	public String editData() throws Exception{
		try {
			String userId = getUserId();
			objctForm.setUserId(userId);
			String roleId = getUserRoleName();
			objctForm.setEntryRole(roleId);
			stationChangeService.editStationChange(objctForm);
			if(null==objctForm.getId() || ("").equals(objctForm.getId())){
				this.getAjaxMessagesJson().setMessage(true, "", "申请岗位异动成功");
			}else{
				this.getAjaxMessagesJson().setMessage(true, "", "编辑岗位异动成功");
			}
		} catch (Exception e) {
			this.handleException(e);
		}
		return RESULT_AJAXJSON;
	}
	
	/**
	 * 初始化删除
	 * @return
	 * @throws Exception
	 */
	public String gotoDel()throws Exception{
		return "gotoDel";
	}
	/**
	 * 删除
	 * @return
	 * @throws Exception
	 */
	public String delData()throws Exception{
		try {
			stationChangeService.deleteById(id);
			this.getAjaxMessagesJson().setMessage(true, "", "删除成功");
		} catch (Exception e) {
			this.handleException(e);
		}
		return RESULT_AJAXJSON;
	}
	/**
	 * 确认提交审批页面
	 * @return
	 * @throws Exception
	 */
	public String gotoSubmitCheck()throws Exception{
		return "gotoSubmitCheck";
	}
	/**
	 * 提交审批
	 * @return
	 * @throws Exception
	 */
	public String submitCheck() throws Exception{
		try {
			stationChangeService.submitCheck(id);
			this.getAjaxMessagesJson().setMessage(true, "", "提交审批成功");
			
		} catch (Exception e) {
			this.handleException(e);
		}
		return RESULT_AJAXJSON;
	}
	
	public IStationChangeService getStationChangeService() {
		return stationChangeService;
	}
	public void setStationChangeService(IStationChangeService stationChangeService) {
		this.stationChangeService = stationChangeService;
	}
	public StationChangeForm getObjctForm() {
		return objctForm;
	}
	public void setObjctForm(StationChangeForm objctForm) {
		this.objctForm = objctForm;
	}
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public List<StationChangeWrapper> getWrapperList() {
		return wrapperList;
	}
	public void setWrapperList(List<StationChangeWrapper> wrapperList) {
		this.wrapperList = wrapperList;
	}

	@SuppressWarnings("unchecked")
	public List getChangeTypeList() {
		return changeTypeList;
	}

	@SuppressWarnings("unchecked")
	public void setChangeTypeList(List changeTypeList) {
		this.changeTypeList = changeTypeList;
	}
	
	
}
